package com.yyfax.pay.third.model.to.fuiou.xml;

import org.apache.commons.lang3.StringUtils;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.io.xml.QNameMap;
import com.thoughtworks.xstream.io.xml.StaxDriver;
import com.yyfax.framework.model.Content;
import com.yyfax.pay.third.model.to.fuiou.PayOrderFuiouContent;


@XStreamAlias("payforrsp")
public class PayoutOrderFuiouContent extends Content{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1718608092767145141L;
	
	/**
	 * 受理成功
	 */
	public static final String SUCCESS = "000000";

	/**
	 * 响应码
	 */
	private String ret;
	
	/**
	 * 响应描述
	 */
	private String memo;
	
	
	/**
	 * 请求内容
	 */
	@JsonIgnore
	private String reqContent;

	public String getRet() {
		return ret;
	}

	public void setRet(String ret) {
		this.ret = ret;
	}

	public String getMemo() {
		return memo;
	}

	public void setMemo(String memo) {
		this.memo = memo;
	}
	
	public String getReqContent() {
		return reqContent;
	}

	public void setReqContent(String reqContent) {
		this.reqContent = reqContent;
	}
	
	/**
	 * 判断富友代付是否成功
	 * 
	 * @author buyi
	 * @date 2018-05-12 02:23:36
	 * @since v2.1.5
	 *
	 * @return
	 */
	public boolean isSuccess(){
		//代付接口返回000000 表示富友受理成功，返回其他结果全部为失败
		return StringUtils.equals(getRet(), SUCCESS);
	}

	/**
	 * 该实体转换成XML字符串
	 * 
	 * @author heizq
	 * @date 2017-4-12 10:52:52
	 * @since v1.0.0
	 * @return 返回XML字符串
	 */
	public String toXml() {
		QNameMap qmap = new QNameMap();
		qmap.setDefaultPrefix("");
		StaxDriver staxDriver = new StaxDriver(qmap);
		XStream xstream = new XStream(staxDriver);
		xstream.autodetectAnnotations(true);
		xstream.ignoreUnknownElements();
		return xstream.toXML(this);
	}

	/**
	 * XML字符串转换成实体{@link PayOrderFuiouContent}
	 * 
	 * @author heizq
	 * @date 2017-4-12 10:53:28
	 * @since v1.0.0
	 * @param xml
	 * @return 返回{@link PayOrderFuiouContent}
	 */
	public static PayoutOrderFuiouContent fromXml(String xml) {
		QNameMap qmap = new QNameMap();
		qmap.setDefaultPrefix("");
		StaxDriver staxDriver = new StaxDriver(qmap);
		XStream xstream = new XStream(staxDriver);
		xstream.autodetectAnnotations(true);
		xstream.ignoreUnknownElements();
		xstream.alias("payforrsp", PayoutOrderFuiouContent.class);
		return (PayoutOrderFuiouContent) xstream.fromXML(xml);
	}
}
